package hbt.dao;

import hbt.util.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import entities.Materia;

public class HibernateMateriaDAO {
	private static SessionFactory sf;
	private static HibernateMateriaDAO instancia;
	
	public static HibernateMateriaDAO getInstancia(){
		if(instancia == null)
			instancia = new HibernateMateriaDAO();
		if(sf == null)
			sf = HibernateUtil.getSessionFactory();
		return instancia;
	}
	
	public void grabarMateria(Materia materia){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(materia);
		session.getTransaction().commit();
		session.flush();
		session.close();
	}
}
